<!--#include file="../nav/account_top.php" -->
<style type="text/css">
 



/* 搜索框 */
.main_content_search{
float:right;
}


/* 菜品套餐加载表格 */
#tbnobody{
display:none;
text-align:center;
}
#tbloading{
display:none;
text-align:center;
}
#tbdata{
margin:20px auto;
display:none;
}


table.goodstb{
width:100%;
border-collapse:collapse;
margin-bottom:20px;
font-size:12px;
color:#555;
}
table.goodstb tr{
border:1px solid #eee;
}
table.goodstb td.goodstb_td{
text-align:left;
vertical-align:top; 
padding:15px;
background-color:#FcFcFc;
} 
table.goodstb td.goodstb_td_l{
width:80%;
}
table.goodstb td.goodstb_td_r{
width:20%;
text-align:center
}
div.goods_title{
font-size:14px;
font-weight:bold;
margin-bottom:10px;
}
div.goods_content{
font-size:14px;
margin-bottom:10px;
color:#666666;
}
div.goods_vege{
margin:10px auto;
position:relative;
}
div.vegeitem{
float:left;
border:1px dashed #CCCCCC;
padding:5px 10px;
margin-right:10px;
margin-bottom:10px;
color:#006600
}


div.goods_edate{
margin:10px auto;
color:#333333;
}



div.goods_alert{
margin:10px auto;
}
div.goods_alert span{
 
} 

div.goods_price{
font-size:16px;
font-weight:bold;
margin:20px auto;
color:#FF6666;
}
div.goods_btn{
margin:10px auto;
}


/* page */
.comboslt{
float:left;
}
ul.menuul{
padding:0px;
margin:0px;
list-style:none;
}
ul.menuul li{
float:left;

}
ul.menuul li a{
display:block;
margin-right:10px;
padding:0px 8px;
line-height:30px;
height:30px;
color:#666666;
text-decoration: none;
}
ul.menuul li a:hover{
text-decoration: none;
}
ul.menuul li.on a{
background-color:#87B4DF;
color: #FFFFFF;
text-decoration: none;
}
ul.menuul li.on a:hover{
text-decoration: none;
}

 
</style>
<div class="main_content_title">
	<span>选菜</span>
	<div class="main_content_search" style="display:none">
		<form action="/account_buy/search" method="get" onsubmit="return fnToSearch()" id="searchform">
			<input type="text" class="searchs" id="keywords" name="keywords" value="" maxlength="10" />
			<input type="submit" class="btn_gray" value="搜索" />
		</form>
	</div>
</div>
<div class="main_content_main">
	<div style="margin:5px auto;position:relative;text-align:right">
		<select id="sortval" class="textBox" onchange="fnFilter()">
			<optgroup label="排序">
				<option selected="selected" value="">默认排序</option>
				<option value="1">按价格 从高到低</option>
				<option value="2">按价格 从低到高</option>
				<option value="3">按可送货时间 远->近</option>
				<option value="4">按可送货时间 近->远</option>
				<option value="5">按发布时间 新->旧</option>
				<option value="6">按发布时间 旧->新</option>
			</optgroup>
		</select>  
	</div>
	<div class="margin10">
		<div id="tbnobody">
			暂无
		</div>
		<div id="tbloading">
			<img src="/misc/images/account/loading.gif" title="正在加载" />
		</div>
		<div id="tbdata">
			<div style="margin:10px auto;color:#666666;" >
				固定套餐
			</div>
			<div id="tbdata_gd">
				
			</div>
			<div style="margin:10px auto;color:#666666;" >
				组合套餐
			</div>
			<div id="tbdata_zh">
				
			</div>
		</div>	
	</div>
	<div id="grids" style="display:none"></div>
	<div style="height:10px;"></div>
</div>
<script type="text/javascript">
var url_list   =  '/account_buy/index_list';
$().ready(function(){
	o2js.build('o2grid');
	o2js.build('ymprompt');
	/* 组装表格 */	
	grids = new o2Grid({
		bind:'grids', 
		url:url_list,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		rowNum:1000,
		cols:[
		],
		beforefunc:function(){
			$('#tbdata').hide(); 
			$('#tbnobody').hide(); 
			$('#tbloading').show();
		},
		runfunc:function(obj){
			var details = obj.results; 
			if(details.length == 0){
				$('#tbdata').hide();
				$('#tbloading').hide();
				$('#tbnobody').show();
			}else{
				$('#tbloading').hide();
				$('#tbnobody').hide();
				$('#tbdata').show();
			}
			fnZuZhuangData(details);
		}
	});
	fnFilter();	
});
/* 加载数据 */
function fnFilter(){
	grids.setBaseParams({
		sortval:$('#sortval').val()
	}); 
	grids.load(1);
}

/* 显示数据 */
function fnZuZhuangData(allrs){
	var html_gd = '';
	var html_zh = '';
	for(var i=0; i<allrs.length; i++){
		var html='';
		var obj = allrs[i];
		html += '	<table class="goodstb">';
		html += '		<Tr>';
		html += '			<td class="goodstb_td goodstb_td_l">';
		html += '				<div class="goods_title">';
		html += obj.name;
		html += '				</div>';
		html += '				<div class="goods_content">';
		html += obj.remark; 
		html += '				</div>';
		html += '				<div class="goods_vege">';
		for(var k=0; k<obj.combo_item.length; k++){
			var citem = obj.combo_item[k];
			html += '					<div class="vegeitem">';
			html += citem.vege_name;
			if(obj.type=='0'){
				html += '						<span>'+citem.vege_num+' 份</span>';
			}
			html += '					</div>';
		}
		html += '					<div class="clear"></div>';
		html += '				</div>';
		html += '			<div class="goods_edate">';
		html += '可配送时间：<span>'+obj.sendbdate+'</span> 至 <span>'+obj.sendedate+'</span>';
		html += '			</div>';
		html += '			</td>';
		html += '			<td class="goodstb_td goodstb_td_r">';
		if(obj.type=='0'){
			html += '				<div class="goods_price">';
			html += '￥'+obj.price; 
			html += '				</div>';
		}else{
			html += '				<div class="goods_alert">';
			html += '最少选菜<span class="red">'+obj.min_num+'份</span> <span class=" ">或</span> <span class="red">'+obj.min_price+'元</span>';
			html += '				</div>';
		}
		html += '				<div class="goods_btn">';
		if(obj.type=='0'){
			html += '					<button class="btn_red" onclick="fnBuy('+obj.id+')">加入购物车</button>';
		}else{
			html += '					<button class="btn_red"  onclick="fnBuySlt('+obj.id+')">选菜</button>';
		}
		html += '				</div>';
		html += '			</td>';
		html += '		</Tr>';
		html += '	</table>	';	
		if(obj.type=='0'){
			html_gd += html;
		}else{
			html_zh += html;
		}
	}					
	$('#tbdata_gd').html(html_gd);
	$('#tbdata_zh').html(html_zh);
}



/* 固定套餐购买 */
function fnBuy(id){
	fnLoading();
  $('button').attr('disabled','disabled');
	$.post(
		'/account_buy/fixbuy',
		{
			id:id
		},
		function(e){
			fnLoadingEnd();
  		$('button').attr('disabled','');
			var ok = errorHandler(e);
			if(ok && ok.success=="1"){　 
				ymPrompt.succeedInfo({
					message:'<div class="m5 f14 fb" >添加成功！</div><br>购物车总共 '+ok.nums+' 件商品，商品合计 <span class="red">￥'+ok.price_total+'</span>',
					width:350,
					height:200,
					handler:fnBuyOnBtn,
					btn:[['去购物车结算','yes'],['继续购买','no']]
				});
			}
		}
	);
}
/* 按钮返回获取 */
function fnBuyOnBtn(tp){
	if(tp=='yes'){
		jumpTo('/account_cart/index');
	}
}

/* 选菜购买 */
function fnBuySlt(id){
	ymPrompt.close();
	ymPrompt.win({
		title:'选菜购买',
		fixPosition:true,
		maxBtn:true,
		width: 700, 
		height: 540,
		iframe:{
			src:'/account_buy/sltbuy?id='+id+'&endfunc=fnBuySltEnd'
		}
	});
}
function fnBuySltEnd(ok){
	ymPrompt.close();
	ymPrompt.succeedInfo({
		message:'<div class="m5 f14 fb" >添加成功！</div><br>购物车总共 '+ok.nums+' 件商品，商品合计 <span class="red">￥'+ok.price_total+'</span>',
		width:350,
		height:200,
		handler:fnBuyOnBtn,
		btn:[['去购物车结算','yes'],['继续购买','no']]
	});
}

/* 搜索提交前 */
function fnToSearch(){
	var keywords = $.trim($('#keywords').val());
	$('#keywords').val(keywords);
	if(keywords == ''){
		ymPrompt.alert({message:'请输入搜索关键字',handler:function(){
			$('#keywords').focus();
		}});
		return false;
	}
	return true;
}
</script>
<!--#include file="../nav/account_bottom.php" -->